home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
tn3270
/
apistg.c
< prev
next >
Wrap
Text File
|
1992-04-17
|
6KB
|
257 lines
/*
* tn3270 for the Macintosh Source Code
* Brown University Computing and Information Services
* Version 2.4d7 April, 1992
* Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
* Peter John DiCamillo.
*
* Permission is granted to any individual or institution to use, copy,
* or redistribute the binary version of this software and its
* documentation provided this notice and the copyright notices are
* retained. Permission is granted to any individual or non-profit
* institution to use, copy, modify, or redistribute the source files
* of this software provided this notice and the copyright notices are
* retained. This software may not be distributed for profit, either
* in original form or in derivative works, nor can the source be
* distributed to other than an individual or a non-profit institution.
* Any individual or group interested in seeing and/or using these
* source files but who are prevented from doing so by the above
* constraints should contact Don Wolfe, Assistant Vice-President for
* Computer Systems at Brown University, (401) 863-7250, for possible
* software licensing of the source developed at Brown.
*
* Brown University and Peter John DiCamillo make no representations
* about the suitability of this software for any purpose.
*
* BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
* EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
* INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#if !defined(USEDUMP)
#include "maclib.h"
#include "termdef.h"
#include "tn3270funcs.h"
#include "globals.h"
#else
#pragma load "tn3270DumpFile"
#endif
#pragma segment api
#define PARAMNEEDED 5
#define CLIENTNEEDED 2
#define DATANEEDED 5
void initparamblocks(void)
{
memset(¶mqueue, 0, sizeof(queueinfo));
strcpy(paramqueue.name, "Param");
paramqueue.elemsize = sizeof(paramrec);
paramqueue.minavail = PARAMNEEDED;
}
void initclientrecs(void)
{
memset(&clientqueue, 0, sizeof(queueinfo));
strcpy(clientqueue.name, "Client");
clientqueue.elemsize = sizeof(clientrec);
clientqueue.minavail = CLIENTNEEDED;
}
void initdatablocks(void)
{
memset(&dataqueue, 0, sizeof(queueinfo));
strcpy(dataqueue.name, "Data");
dataqueue.elemsize = sizeof(datarec);
dataqueue.minavail = DATANEEDED;
}
void endparamblocks(void)
{
endqueue(¶mqueue);
}
void endclientrecs(void)
{
endqueue(&clientqueue);
}
void enddatablocks(void)
{
endqueue(&dataqueue);
}
void endqueue(queueinfo *qp)
{
qctl *current, *next;
next = qp->first;
while (next != 0) {
current = next;
next = (qctl *)current->next;
DisposPtr((Ptr)current);
}
qp->first = 0;
qp->stgerr = 0;
qp->spare = 0;
}
void addparamblocks(void)
{
addqueue(¶mqueue);
}
void addclientrecs(void)
{
addqueue(&clientqueue);
}
void adddatablocks(void)
{
addqueue(&dataqueue);
}
void addqueue(queueinfo *qp)
{
qctl *current;
short avail, i, needed;
OSErr rc;
/* unsigned char msg[120]; ****** */
if (qp->stgerr) return;
avail = 0;
current = qp->first;
while (current != 0) {
if (current->inuse == 0) {
avail++;
}
current = (qctl *)current->next;
}
/* queue debugging code ********
if (avail != qp->spare) {
sprintf(msg, "Queue %s: avail was %d, now %d", qp->name, qp->spare, avail);
cs.dblevel = 1;
dbdlg(msg);
cs.dblevel = 0;
qp->spare = avail;
} ******** */
needed = qp->minavail - avail;
if (needed <= 0) return;
for (i = 0; i < needed; i++) {
rc = extendqueue(qp);
if (rc != noErr) break;
}
if (rc != noErr) qp->stgerr = 1;
}
OSErr extendqueue(queueinfo *qp)
{
qctl *new, *current;
new = (qctl *)myNewPtr(qp->elemsize, 0);
if (new == 0) {
return(mFulErr);
}
memset(new, 0, qp->elemsize);
if (qp->first == 0) {
qp->first = new;
return(noErr);
}
current = qp->first;
while (current->next != 0) {
current = (qctl *)current->next;
}
current->next = (unsigned char *)new;
return(noErr);
}
PPCParamBlockPtr newparamblock(void)
{
paramrec * prp;
prp = (paramrec *)getnew(¶mqueue);
if (prp == 0) return(0);
else return(&(prp->pb));
}
clientinfo * newclientrec(void)
{
clientrec * crp;
crp = (clientrec *)getnew(&clientqueue);
if (crp == 0) return(0);
else return(&(crp->client));
}
datainfo * newdatablock(void)
{
datarec * drp;
drp = (datarec *)getnew(&dataqueue);
if (drp == 0) return(0);
else return(&(drp->data));
}
qctl * getnew(queueinfo *qp)
{
qctl *current;
/* Note: this code is designed so that if it is interrupted
by a copy of itself running at interrupt level, it will
not allocated the same element twice. */
current = qp->first;
while (current != 0) {
if (current->inuse == 0) {
if (current->pend_inuse == 0) {
current->pend_inuse == 1;
if (current->inuse == 0) {
current->inuse = 1;
current->pend_inuse = 0;
return(current);
}
else {
current->pend_inuse = 0;
}
}
}
current = (qctl *)current->next;
}
return(0);
}
void disposparamblock(PPCParamBlockPtr p)
{
disposelem((unsigned char *)p, ¶mqueue);
}
void disposclientrec(clientinfo *p)
{
disposelem((unsigned char *)p, &clientqueue);
}
void disposdatarec(datainfo *p)
{
disposelem((unsigned char *)p, &dataqueue);
}
void disposelem(unsigned char *s, queueinfo *qp)
{
qctl * delete_elem, *current;
s -= sizeof(qctl);
delete_elem = (qctl *)s;
current = qp->first;
while (current != 0) {
if (current == delete_elem) {
current->inuse = 0;
return;
}
current = (qctl *)current->next;
}
}